package com.example.templateapp.ui.chat

import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.templateapp.R
import com.example.templateapp.databinding.ActivityChatBinding
import com.example.templateapp.model.ChatInfoVo
import com.example.templateapp.ui.adapter.ChatAdapter
import com.example.templateapp.ui.base.BaseAppCompatActivity
import com.example.templateapp.util.DateFormatUtils

class ChatActivity : BaseAppCompatActivity() {

    private val binding: ActivityChatBinding by binding(R.layout.activity_chat)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val adapter = ChatAdapter(this)
        binding.rv.layoutManager = LinearLayoutManager(this, RecyclerView.VERTICAL, false)
        binding.rv.adapter = adapter
        val list = mutableListOf<ChatInfoVo>()

        list.add(ChatInfoVo(true, "你好", DateFormatUtils.long2Str(System.currentTimeMillis())))
        list.add(ChatInfoVo(false, "你好a", DateFormatUtils.long2Str(System.currentTimeMillis())))
        adapter.refresh(list)

        binding.send.setOnClickListener {
            adapter.add(
                ChatInfoVo(
                    true,
                    "你好",
                    DateFormatUtils.long2Str(System.currentTimeMillis())
                )
            )
            binding.rv.smoothScrollToPosition(adapter.itemCount - 1)
        }

        binding.receive.setOnClickListener {
            adapter.add(
                ChatInfoVo(
                    false,
                    "你好a",
                    DateFormatUtils.long2Str(System.currentTimeMillis())
                )
            )
            binding.rv.smoothScrollToPosition(adapter.itemCount - 1)
        }


    }
}